﻿using WMM.Tapioca;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Text;
using System.Xml;
using System.Net;
using System.Configuration;
using WMM.Tapioca.Instance;
using System;
using WMM.Tapioca.Utilities;

namespace WMM.Test.Tapioca
{
    /// <summary>
    /// Summary description for UkGaapSamples20080620UnitTest
    /// </summary>
    [TestClass]
    public class UkGaapSamples20080620UnitTest
    {
        static XmlCachingResolver resolver;

        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            bool useProxy = Boolean.Parse(ConfigurationManager.AppSettings["UseProxy"]);
            resolver = new XmlCachingResolver(true, useProxy);    
        }

        public UkGaapSamples20080620UnitTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void LoadAccountingPoliciesDimensionXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("accounting-policies-dimension.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadBalanceSheetIndividualForeignCurrencyXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("balance-sheet-individual-foreign-currency.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadBalanceSheetIndividualSchedule4Format1Xbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("balance-sheet-individual-schedule-4-format-1.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadCashFlowStatementGroupXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("cash-flow-statement-group.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadCashFlowStatementCopyXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("cash-flow-statement - Copy.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadDetailedProfitLossAccountDimensionXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("detailed-profit-loss-account-dimension.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);           
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadDetailedProfitLossAccountXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("detailed-profit-loss-account.xml"), resolver);
            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadHistoricalCostProfitsLossesXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("historical-cost-profits-losses.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadNotePensionFrs17AmendmentsXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("note-pension-frs17-amendments.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadNotePensionXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("note-pension.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadNoteSegmentReportingDimensionExtensionXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("note-segment-reporting-dimension-extension.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadNoteTangibleFixedAssetsDimensionXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("note-tangible-fixed-assets-dimension.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);           
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadNoteTaxationXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("note-taxation.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadProfitLossAccountGroupSchedule4Format1DimensionXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("profit-loss-account-group-schedule-4-format-1-dimension.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadProfitLossAccountIndividualSchedule4Format1Xbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("profit-loss-account-individual-schedule-4-format-1.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);           
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        [TestMethod]
        public void LoadStatementTotalRecognisedGainsLossesDimensionXbrl()
        {
            InstanceDocument XbrlDoc = new InstanceDocument(GetRelativePathForDocument("statement-total-recognised-gains-losses-dimension.xml"), resolver);

            XbrlManager xbrlManager = new XbrlManager(XbrlDoc);            
            xbrlManager.Validate();

            Assert.IsTrue(XbrlDoc.Dts.ValidatedInstance, "The instance document was not validated.");
        }

        private string GetRelativePathForDocument(string DocFilename)
        {
            StringBuilder RelativePath = new StringBuilder();
            RelativePath.AppendFormat("..\\..\\..\\WMM.Test.Tapioca\\uk-gaap-samples-2008-06-20\\samples\\{0}", DocFilename);            
            return RelativePath.ToString();
        }
    }
}
